<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org"
	  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	  layout:decorator="common/layout"
	  xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
	<title>用户列表</title>
</head>
<body>
<section layout:fragment="top_menu" style="text-align: right;padding-right: 20px">
	<div>
		<input type="button" class="new_button_yellow input_add" onclick="location.href='/admin/user/new'" value="添加">
		<!--<a href="/users/new">添加员工</a>-->
	</div>
</section>


<section layout:fragment="content">
	<div class="list" style="font-size:0.9em;">
		<table id="list">
			<tr class="header">
				<td>序号</td>
				<td>工号</td>
				<td>姓名</td>
				<td>手机号</td>
				<td>角色</td>
				<td shiro:hasRole="ADMIN">店铺名</td>
				<td>操作</td>
			</tr>
			<tbody id="list_body">
			<tr th:each="item,row:${rows}" th:id="${#strings.concat('item_', item.id)}" th:class="${#strings.concat('item_', row.index%2)}">
				<td th:text="${row.index+1 + (page-1)*perpage}">
				</td>
				<td th:text="${item.employeeNo}"></td>
				<td th:text="${item.username}"></td>
				<td th:text="${item.mobile}"></td>
				<td th:text="${item.roleModel}?${item.roleModel.name}:'未指定'"></td>
				<td shiro:hasRole="ADMIN" th:text="${item.storeName}"></td>
				<td>
					<a class="icon-remove" th:href="${#strings.concat('javascript:userRemove(',item.id, ')')}">删除</a>
					&nbsp;&nbsp;
					<a class="icon-edit" th:href="${#strings.concat('/admin/user/',item.id)}">编辑</a>
				</td>
			</tr>
			</tbody>
		</table>
		<div class="paginator">
			<ul>
				<li><</li>
				<li>1</li>
				<li>2</li>
				<li>3</li>
				<li class="dot">...</li>
				<li>9</li>
				<li>></li>
			</ul>
		</div>
	</div>
</section>

<section layout:fragment="extra_scripts">
	<script src="/js/bower_components/bootpag/lib/jquery.bootpag.js"></script>
	<script src="/js/paginator.js"></script>

	<script th:inline="javascript">
		$(function(){
			Paginator.init(
					[[${total}]],
					function(page){
						var querys={};
						querys["page"] = page;
						var user_id = [[${user.kind}]];
						var url = "/admin/user/waiters?" + $.param(querys);
						if(user_id.$name=="ADMIN") {
							url = "/admin/user/users?" + $.param(querys);
						}
						self.location.href = url;
					},
					[[${page}]]
			);
		});

		function userRemove(user_id) {
			if (!confirm("确定删除吗？")) {
				return;
			}
			$.post("/admin/user/" + user_id, {_method: "DELETE"}, function (data) {
				if (data.success) {
					self.location.reload();
				} else {
					alert(data.message);
				}
			});
		}
		;

	</script>
</section>

</body>


</html>